package core;

import JitUtils.FileHash;
import fileoperation.FileDeletion;
import repository.Repository;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;

public class JitHash {
    /**
     * Init repository in your working area.
     * @param filename
     * @throws IOException
     */
    /**
     * 修改：调用tree和blob中的方法生成hash值，再考虑持续化到本地
     * @param filename
     * @throws IOException
     */
    public static void hash(String filename) throws Exception {
        /* Todo: You should pass the filename in this function, and generate a hash file in your repository.
        *   Add your code here.*/
        File file = new File(filename);
        String str = null;
        if(file.isFile()) {
             str = FileHash.fileHash(file,"1").getId();
        }else{
            str = FileHash.hashOfDic(file).getId();
            System.out.println(str);
        }
        if(str != null) {
            String dicObjects = new File(".").getCanonicalPath() + File.separator+ ".jit" + File.separator + "objects" + File.separator + str.substring(0, 2);
            File file1 = new File(dicObjects);
            file1.mkdir();
            String pathObjects = new File(".").getCanonicalPath() + File.separator+ ".jit" + File.separator + "objects" + File.separator + str.substring(0, 1) + File.separator + str.substring(2);
            File file2 = new File(dicObjects);
            file2.createNewFile();
        }

    }

}

